#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
    bool itIsAlphanumeric(char tmp)
    {
        if (tmp >= 'a' && tmp <= 'z' || tmp >= '0' && tmp <= '9')
            return true;
        return false;
    }
    bool isPalindrome(string s) {
        for (auto& ch : s)
        {
            if (ch >= 'A' && ch <= 'Z')
            {
                ch += 'a' - 'A';
            }
        }
        int begin = 0;
        int end = s.size() - 1;
        while (begin < end)
        {
            while (!itIsAlphanumeric(s[begin]) && begin < end)
            {
                ++begin;
            }
            while (!itIsAlphanumeric(s[end]) && begin < end)
            {
                --end;
            }
            if (s[begin] != s[end])
            {
                return false;
            }
            else
            {
                ++begin; --end;
            }
        }
        return true;
    }
};
int main()
{
    string s("race a car");
    cout << Solution().isPalindrome(s) << endl;
    return 0;
}